package weekend3;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("two");
        System.out.println("c:"+c);

        System.out.println(c.size());

        System.out.println("是否为空集："+c.isEmpty());

        // c.clear();
        //System.out.println("c:"+c);

        System.out.println(c.contains("two"));

        c.remove("two");
        System.out.println("c:"+c);

        Collection<String> c1=new ArrayList<>();
        c1.add("one");
        c1.add("two");
        c1.add("three");
        c1.add("six");

        System.out.println(c.containsAll(c1));

        //c1.addAll(c);
        //System.out.println(c1);

        //c.retainAll(c1);//取交集
        //System.out.println("c:"+c);

        //c.removeAll(c1);//删交集
        //System.out.println("c:"+c);

        Iterator it=c.iterator();
        while(it.hasNext()){
            String str=(String)it.next();
            System.out.println(str);
        }
        //增强for循环
        for(String str:c){
            System.out.println(str);
        }

    }

}
